package cn.glc.daily.life.web.convert;

import cn.glc.daily.life.infrastructure.po.UserAuthsPo;
import cn.glc.daily.life.infrastructure.po.UserPo;
import cn.glc.daily.life.model.dto.UserSignupDto;
import cn.glc.daily.life.model.to.UserTo;
import cn.glc.daily.life.model.vo.user.UserAuthsVo;
import cn.glc.daily.life.model.vo.user.UserVo;
import cn.simon.free.tools.utils.DateUtils;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import static cn.glc.daily.life.model.enums.UserStatusEnums.signup;

/**
 * 用户转换类
 *
 * @author simon
 * @date 2020/9/21 13:27
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@Mapper
public interface UserConvert {
    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);


    /**
     * 用户授权po 转 vo
     *
     * @param userAuthsPo
     * @return
     */
    UserAuthsVo userAuthsPoToUserAuthsVo(UserAuthsPo userAuthsPo);

    /**
     * 用户注册对象转换
     *
     * @param userSignupDto
     * @param uid
     * @return
     */
    default UserPo userSignupDtoToUser(UserSignupDto userSignupDto, long uid) {
        UserPo userPo = new UserPo();
        userPo.setUid(uid);
        userPo.setNickName(userSignupDto.getNickName());
        userPo.setStatus(signup.name());
        userPo.setCreateTime(DateUtils.now());
        return userPo;
    }

    /**
     * 内部对象to 转 vo
     *
     * @param details
     * @return
     */
    UserVo userToUserVo(UserTo details);
}
